import moment       from 'moment'
import Mapwindow    from './Mapwindow'
import decimg       from './images/sjgj.png'
import fatigueimg   from './images/fatigue.png'
import parkingimg   from './images/parking.png'
import dhimg        from './images/ignition.png'
import xhimg        from './images/stalled.png'
import dstcimg      from './images/idle.png'
import chaosu       from './images/chaosu.png'
import chu          from './images/chu.png'
import ru           from './images/ru.png'
import MapPoint     from './MapPoint'
import unit         from '@/util/unit'
import {getAddress} from '@/plugin/Map/Mapaddress'

class Mapalarm {

	marker = null
	icons = [decimg,decimg,decimg,decimg,chaosu,fatigueimg,ru,chu,parkingimg,chaosu]
	imgsize = [[32,53],[32,53],[32,53],[32,53],[32,53],[32,53],[32,53],[32,53],[32,53],[32,53]]
	isOpenWindow = false
	typestr = ['急加速','急减速','左转弯','右转弯','超速','疲劳驾驶']

	constructor({map,gps,type=1,info = {},isWindow=true}){
		this.map = map;
		this.gps = gps;
		this.info = info;
		this.isWindow = isWindow;
		if(this.gps&&this.gps.lng){
			this.type = type;
			this.info.size = this.imgsize[this.type-1];
			this.info.icon = this.icons[this.type-1];
			this._init();
		}
	}



	_init(){
		let ops = {
        map: this.map,
        point: [this.gps.lng, this.gps.lat],
        mkopts:{
        	icon:new AMap.Icon({image:this.info.icon,imageSize:new AMap.Size(this.info.size[0]/1.5,this.info.size[1]/1.5),size:new AMap.Size(this.info.size[0],this.info.size[1])}),
       		offset: new AMap.Pixel(-this.info.size[0]/1.5/2,-this.info.size[1]/1.5),
        	// angle:this.gps.direction||0
        },
        wdopts:{
        	isOnly:true,
        	width:290,
        	isShow:false,
        	zIndex:202,
        }
    };
  	ops.data = {
  		'驾驶员':this.info.driverName||'--',
    	'告警类型':this.typestr[this.info.type-1],
    	'告警时间':moment(this.info.startTime).format('YYYY-MM-DD HH:mm:ss')
    }

		this.marker = new MapPoint(ops);
	}

	show(){
		this.marker.infowindow.show();
	}

	allshow(){
		this.marker.marker.show();
	}

	allhide(){
		this.marker.marker.hide();
		this.marker.infowindow.hide();
	}

	hide(){
		this.marker.infowindow.hide();
	}

	hidePoint(){
		this.marker.marker.hide();
		this.marker.infowindow.hide();
	}

	showPoint(){
		this.marker.marker.show();
	}

	center(){
		this.map.setCenter(this.marker.marker.getPosition());
	}

}
export default Mapalarm;
